//
//  colors.swift
//  SmartPenSwift
//
//  Created by tql on 2021/2/3.
//

import Foundation
import UIKit

extension UIColor{
    convenience init(hex : String){
        self.init(hex: hex,WithAlpha:1)
    }
    convenience init(hex : String,WithAlpha alpha : CGFloat){
        let scanner  = Scanner(string: hex)
        scanner.scanLocation = 0
        var rgbValue : UInt64 = 0
        scanner.scanHexInt64(&rgbValue)
        
        let r  = (rgbValue & 0xff0000) >> 16
        let g =  (rgbValue & 0x00ff00) >> 8
        let b = (rgbValue & 0x0000ff)
        
        self.init(red: CGFloat(r)/0xff,
                  green:  CGFloat(g)/0xff,
                  blue:  CGFloat(b)/0xff,
                  alpha: alpha
        )
        
       
    }
    convenience init(red : Int, green : Int , blue : Int){
        self.init(red: red,green: green,blue: blue,alpha: 1)
    }
    convenience init(red : Int, green : Int, blue : Int, alpha : CGFloat){
        assert(red >= 0 && red <= 255,"invalid red")
        assert(green >= 0 && green <= 255,"invalid green")
        assert(blue >= 0 && blue <= 255,"invalid blue")
        self.init(red: red,green: green,blue: blue,alpha: alpha)
    }
    static func random() -> UIColor{
        return UIColor(red: .random(in: 0..<1), green: .random(in: 0..<1), blue: .random(in: 0..<1))
    }
    static func customBlackString() -> String{
//        +(NSString *)customBlackString;
        return "151515"
    }
    static func customBlack() -> UIColor{
//        +(UIColor *)customBlack;
        return UIColor(hex: customBlackString())
    }

    static func customRedString() -> String{
//    +(NSString *)customRedString;
        return "FF4E4E"
    }
    static func customRed() -> UIColor{
//    +(UIColor *)customRed;
        return UIColor(hex: customRedString())
    }
    static func customBlueString() -> String{
//    +(NSString *)customBlueString;
        return "1A81F9"
    }
    static func customBlue() -> UIColor{
//    +(UIColor *)customBlue;
        return UIColor(hex: customBlueString())
    }

    static func customGreenString() -> String{

//    +(NSString *)customGreenString;
        return  "53D769"
    }
    static func customGreen() -> UIColor{

//    +(UIColor *)customGreen;
        return UIColor(hex: customGreenString())
    }
    static func customYellowString() -> String{

//    +(NSString *)customYellowString;
        return "FED02F"
    }
    static func customYellow() -> UIColor{

//    +(UIColor *)customYellow;
        return UIColor(hex:  customYellowString())
    }
    static func customOrangeString() -> String{

//    +(NSString *)customOrangeString;
        return "FF8F21"
    }
    static func customOrange() -> UIColor{
//    +(UIColor *)customOrange;
        return UIColor(hex: customOrangeString())
    }
}
